package com.itlaobing.response.status;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet( "/error/status" )
public class ErrorStatusServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        // 设置响应对象和请求对象的编码
        request.setCharacterEncoding( "UTF-8" );
        response.setCharacterEncoding( "UTF-8" );

        // 设置 响应 状态码 和 原因短语
        response.sendError( 404 , "Jin Zhi Ru Nei");

        // 设置 响应头 中的 content-type 字段的值
        response.setContentType( "text/html;charset=UTF-8" );

        PrintWriter out = response.getWriter();

        out.println( "<h3 align= center>" + "Error Status : hello meself " + "</h3>");

        // 输出当前响应的状态码
        this.log( "【" + response.getStatus() + "】");
    }
}
